package com.djhu.freepartner.web.service.impl;

import com.baomidou.mybatisplus.enums.SqlLike;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.djhu.freepartner.bean.Area;
import com.djhu.freepartner.bean.Playtypedict;
import com.djhu.freepartner.service.IAreaService;
import com.djhu.freepartner.service.IPlaytypedictService;
import com.djhu.freepartner.web.control.model.AreaModel;
import com.djhu.freepartner.web.service.IMetaDataService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class MetaDataServiceImpl implements IMetaDataService {

    @Autowired
    private IAreaService areaService;

    @Autowired
    private IPlaytypedictService playtypedictService;

    @Override
    public List<Area> selectAreas(AreaModel areaModel) {
        Wrapper wrapper = new EntityWrapper<Area>();
        ((EntityWrapper) wrapper).setEntity(new Area());
        wrapper.eq("LEVEL_TYPE",areaModel.getLevel());
        if (StringUtils.isNotEmpty(areaModel.getParentid())){
            wrapper.eq("PARENT_ID",areaModel.getParentid());
        }
        if (StringUtils.isNotEmpty(areaModel.getName())){
            wrapper.like("NAME",areaModel.getName(),SqlLike.DEFAULT);
        }
        List<Area> areas = areaService.selectList(wrapper);

        /**
         * 加下不限
         */
        Area area = new Area();
        area.setCitycode("");
        area.setName("不限");
        areas.add(area);
        return areas;
    }

    @Override
    public List<Map<String,Object>> playtypes() {
        Wrapper wrapper = new EntityWrapper<Playtypedict>();
        ((EntityWrapper) wrapper).setEntity(new Playtypedict());
        List<Playtypedict> playtypedicts =  playtypedictService.selectList(wrapper);
        List<Map<String, Object>> arrayList = new ArrayList<>();
        playtypedicts.forEach(playtypedict -> {
            Map<String, Object> objectMap = new HashMap<>();
            objectMap.put("playtype",playtypedict.getPlaytype());
            objectMap.put("playname",playtypedict.getPlayname());
            arrayList.add(objectMap);
        });
        Map<String, Object> objectMap = new HashMap<>();
        objectMap.put("playtype","");
        objectMap.put("playname","不限");
        arrayList.add(objectMap);
        return arrayList;
    }
}
